# Beginning of Makefile

#	FileName: Makefile
#	Purpose: To automate the process of multiple different builds ranging from clean-up, to compilation to tarball of compiled program 
#	Description: make script to automate build processes
#	Modified by Grant Meyers
OBJDIR = ./obj/
OBJS = $(OBJDIR)shutil.o $(OBJDIR)parser.o $(OBJDIR)sshell.o
HDRDIR = ./inc/
HEADER_FILES = $(HDRDIR)shell.h $(HDRDIR)parser.h
SRCDIR = ./src/
EXECUTABLE = sshell
CFLAGS = -Wall
CC = gcc
# End of configuration options

#What needs to be built to make all files and dependencies
all: $(EXECUTABLE)

#Create the main executable
$(EXECUTABLE): $(OBJS)
	$(CC) -o $(EXECUTABLE) $(OBJS)

#Recursively build object files
$(OBJDIR)%.o: $(SRCDIR)%.c
	$(CC) $(CFLAGS) -I$(HDRDIR) -c $< -o $@

#Define dependencies for objects based on header files
#We are overly conservative here, parser.o should depend on parser.h only
$(OBJS) : $(HEADER_FILES)

clean:
	-rm -f $(EXECUTABLE) $(OBJDIR)*.o 

run: $(EXECUTABLE)
	./$(EXECUTABLE)

tarball:
	-rm -f $(EXECUTABLE) $(OBJDIR)*.o 
	(cd .. ; tar czf Meyers_Grant_a3.tar.z shell )

# End of Makefile

